“var1” and “var2” in the upper screen is a local variable, which we

cannot use outside of the “sum” function.

Furthermore, there is a difference in the storage location between

the state and the local variables, that we’ll cover later in this chapter.

2.5.9.3 Global variables

There are quite a few globally available predefined variables in

Solidity that we often use in our code. Some of them are wei, gwei,

blockhash, msg.data, msg.sender, now etc.

Refer to the following code:

// SPDX-License-Identifier: Some Identifier

pragma solidity ^0.8.10;

contract SenderDetails {

address owner;

constructor() {

owner = msg.sender;

}

function getOwner() external view returns (address) {

return owner;

}

}

If you compile, deploy, and run the preceding program, then you will

find

a

value

like

“0xd031A3AAC160f17a87D8D445c4307eFd250c3aed” which is the

address of the Ethereum account holder who is running the contract.

Hence, “msg.sender” is a global variable.

While coding, the programmer must not use these reserved names

for the global variables as a local or state level variable.

2.5.10 Types

Earlier, it was already mentioned that Solidity is a statically typed

language, which means that the variable types are to be declared